Skip to content

Add PeripheralAndroidOptions.addServicesInScanResponse#263

Merged
rohitsangwan01 merged 3 commits into
Navideck:mainfrom
jonasbark:feat/services-in-scan-response
Jun 25, 2026
Merged

Add PeripheralAndroidOptions.addServicesInScanResponse#263
rohitsangwan01 merged 3 commits into
Navideck:mainfrom
jonasbark:feat/services-in-scan-response

Conversation

@jonasbark

Copy link
Copy Markdown
Contributor

Problem

On Android the primary BLE advertisement is capped at 31 bytes. A 128-bit service UUID (18 bytes) plus the device name overflows it, and startAdvertising fails with ADVERTISE_FAILED_DATA_TOO_LARGE. There is currently no way to move service UUIDs into the scan response — only addManufacturerDataInScanResponse exists — so a peripheral that advertises a 128-bit service UUID and a name cannot advertise at all.

Change

Adds PeripheralAndroidOptions.addServicesInScanResponse. When true, advertised service UUIDs are placed in the scan response instead of the primary advertisement packet. The device name is also kept out of the scan response in that case, so a name + 128-bit UUID can't overflow the scan response either. Active scanners still receive every service UUID.

  • Default false → unchanged behavior.
  • Android-only; iOS/Windows manage the advertisement/scan-response split themselves and are unaffected.
  • Pigeon regenerated (only the new field is added to the bindings).

Testing

  • flutter analyze clean.
  • Existing test/android_options_test.dart round-trip passes with the new field.
  • Verified against a real peripheral (Zwift/Rouvy controller emulation) that previously failed with "Data too large" and now advertises successfully.

🤖 Generated with Claude Code

Android caps the primary BLE advertisement at 31 bytes. A 128-bit service
UUID (18 bytes) plus the device name overflows it, so startAdvertising
fails with ADVERTISE_FAILED_DATA_TOO_LARGE.

Add PeripheralAndroidOptions.addServicesInScanResponse: when true,
advertised service UUIDs are placed in the scan response instead of the
primary packet (and the device name is kept out of the scan response so it
can't overflow there either). Active scanners still receive every UUID.
Other platforms manage the advertisement/scan-response split themselves
and are unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 25, 2026 06:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the addServicesInScanResponse option to PeripheralAndroidOptions across Android, iOS, Dart, and Windows platforms. On Android, this option allows putting advertised service UUIDs in the scan response instead of the primary advertisement to prevent packet overflow, while automatically excluding the device name from the scan response if service UUIDs are present. The feedback suggests improving the documentation for addServicesInScanResponse to explicitly mention that the scan response packet is also limited to 31 bytes and to warn about potential overflows when combined with addManufacturerDataInScanResponse.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread pigeon/universal_ble.dart Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 7 changed files in this pull request and generated 1 comment.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@rohitsangwan01 rohitsangwan01 merged commit 42756c3 into Navideck:main Jun 25, 2026
2 checks passed
@navidecklabs navidecklabs requested a review from Copilot June 25, 2026 09:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 7 changed files in this pull request and generated 2 comments.

Comment on lines 152 to +156
val scanResponseBuilder = AdvertiseData.Builder()
.setIncludeTxPowerLevel(false)
.setIncludeDeviceName(localName != null)
// Device name is already included in the primary advertisement when localName != null.
// Keeping it out of the scan response saves space for manufacturer data / service UUIDs.
.setIncludeDeviceName(false)
Comment thread pigeon/universal_ble.dart
Comment on lines 262 to +275
class PeripheralAndroidOptions {
bool? addManufacturerDataInScanResponse;
PeripheralAndroidOptions({this.addManufacturerDataInScanResponse});

/// Put advertised service UUIDs in the scan response instead of the primary
/// advertisement. The Android primary advertisement and scan response are
/// both capped at 31 bytes. A 128-bit service UUID (18 bytes) plus a
/// device name can overflow the primary packet.
/// Note: If this is enabled with `addManufacturerDataInScanResponse`, ensure
/// the combined data fits within the scan response's 31-byte limit.
bool? addServicesInScanResponse;
PeripheralAndroidOptions({
this.addManufacturerDataInScanResponse,
this.addServicesInScanResponse,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants